package com.vimeworks.vimemannager.ejb.utilidades;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.vimeworks.vimemannager.ejb.exeptions.LocatorException;

public class ServiceLocator {

	private static ServiceLocator me;
	
	InitialContext context = null;

	private ServiceLocator() throws LocatorException {
		try {
			context = new InitialContext();
		} catch (NamingException ne) {
			throw new LocatorException(ne);
		}
	}

	public static ServiceLocator getInstance() throws LocatorException {
		if (me == null) {
			me = new ServiceLocator();
		}
		return me;
	}

	public static Object obtenerEJB(String nombre) throws LocatorException {
		try {
			return getInstance().context.lookup(nombre);
		} catch (NamingException e) {
			e.printStackTrace();
			return null;
		}
	}

}
